export default {
  saveFeature: function (typeName, featureProperties) {
    const url = agcim.net.apiPath.dynamic_saveFeature;
    const data = {
      spatialIndex: typeName,
      agSrvFeatureProperties: featureProperties,
    };
    return new Promise((resolve, reject) => {
      agcim.net.axiosWraper.getDataByPost(url, JSON.stringify(data), { headers: { "Content-Type": "application/json" } }).then(
        response => {
          if (response.success) {
            resolve(response);
          } else {
            reject(response);
          }
        },
        error => {
          reject(error);
        }
      );
    });
  },

  updateFeature: function (typeName, featureProperties) {
    const url = agcim.net.apiPath.dynamic_updateFeature;
    const data = {
      spatialIndex: typeName,
      agSrvFeatureProperties: featureProperties,
    };
    return new Promise((resolve, reject) => {
      agcim.net.axiosWraper.getDataByPost(url, JSON.stringify(data), { headers: { "Content-Type": "application/json" } }).then(
        response => {
          if (response.success) {
            resolve(response);
          } else {
            reject(response);
          }
        },
        error => {
          reject(error);
        }
      );
    });
  },

  deleteFeature: function (typeName, ids) {
    const data = new FormData();
    data.append("spatialIndex", typeName);
    data.append("ids", ids);
    const url = agcim.net.apiPath.dynamic_deleteFeature;
    return new Promise((resolve, reject) => {
      agcim.net.axiosWraper.getDataByPost(url, data).then(
        response => {
          if (response.success) {
            resolve(response);
          } else {
            reject(response);
          }
        },
        error => {
          reject(error);
        }
      );
    });
  },
};
